#ifndef CONTACTTABLEMODEL_H
#define CONTACTTABLEMODEL_H

#include <QAbstractTableModel>
#include <QPixmap>

#include "contactitem.h"
#define KeyRole     (Qt::UserRole+0)

typedef QList< ContactItem > ContactList ;

#include <QStyledItemDelegate>
class QTextBrowser;
class ContactItemDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    ContactItemDelegate(QObject * parent = 0);
    virtual ~ContactItemDelegate();

    virtual void	paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;

private:
    QTextBrowser* browser;
};

class ContactTableModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    ContactTableModel(QObject *parent=0);
    ContactTableModel(ContactList list, QObject *parent=0);

    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;

    bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex());
    bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex());

    void updateRow(ContactItem const& item);

    ContactItem& findContact(QString jid)
    {
        ContactItem item;
        item.setJid(jid.toStdString());
        return contacts[contacts.indexOf(item)];
    }

private:
    ContactList contacts;
};

#endif // CONTACTTABLEMODEL_H
